﻿using SocketCore.Common.Event;

var eventHub = new SocketEventHub();

// 订阅所有类型的事件
eventHub.OnEvent += (sender, e) =>
{
    switch (e.Type)
    {
        case SocketEventType.Log:
            var logMessage = e.GetData<SocketLogMessage>();
            Console.WriteLine($"[LOG] {logMessage.Level}: {logMessage.Message}");
            break;

        case SocketEventType.Connect:
            var connectedMessage = e.GetData<SocketClientConnect>();
            Console.WriteLine($"[CONNECT] Client {connectedMessage.ClientInfo} connected");
            break;

        case SocketEventType.MessageReceived:
            var receivedMessage = e.GetData<SocketClientMessage>();
            Console.WriteLine($"[MESSAGE] From {receivedMessage.ClientInfo}: {receivedMessage.Message}");
            break;
    }
};

eventHub.RaiseEvent(SocketEventType.Log, new SocketLogMessage { Level = LogLevel.Info, Message = "aaaaa" });

Console.ReadKey();
//// See https://aka.ms/new-console-template for more information
//using Microsoft.Extensions.Configuration;
//using Microsoft.Extensions.Primitives;
//using Serilog;
//using Spectre.Console;
//using System.Reflection;
//using WorkTool;
//using WorkTool.Helpers;

//Log.Logger = new LoggerConfiguration()
//            .MinimumLevel.Debug() // 设置最低日志级别为 Debug
//            .WriteTo.File(
//                path: "Logs/WorkTool-.log", // 指定日志目录和文件名模板
//                rollingInterval: RollingInterval.Day, // 按天滚动
//                restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, // 该接收器的最低级别
//                outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}", // 自定义输出格式
//                retainedFileCountLimit: 30, // 保留最近30天的日志文件
//                fileSizeLimitBytes: 10 * 1024 * 1024, // 单个文件最大10MB
//                rollOnFileSizeLimit: true, // 达到文件大小限制后也滚动
//                shared: true // 允许多个进程共享同一个日志文件
//            )
//            .CreateLogger();

//Console.Title = $"Work Tool [Version:{Assembly.GetExecutingAssembly().GetName().Version}]";

//var config = new ConfigurationBuilder()
//    .SetBasePath(Directory.GetCurrentDirectory())
//    .AddJsonFile(
//        path: "calendarSettings.json",
//        optional: true,
//        reloadOnChange: true)
//    .AddJsonFile(
//        path: "appsettings.json",
//        optional: false,
//        reloadOnChange: true).Build();
//SettingsHelper.ChangeSettings(config);
//ChangeToken.OnChange(
//    () => config.GetReloadToken(),
//    () =>
//    {
//        SettingsHelper.ChangeSettings(config);
//        Console.WriteLine("配置已更新！");
//    }
//);

//// 创建选项列表
//var options = new List<(int Index, string Description)>
//        {
//            new (1, "git cherry-pick"),
//            new (2, "工作月报表"),
//            new (3, "假期查询"),
//            new (4, "Base64转文件"),
//            new (5, "合并PDF"),
//            new (0, "退出系统")
//        };
//while (true)
//{
//    UpdateHelper.Update();
//    try
//    {
//        AnsiConsole.Clear();
//        //CalendarHelper.CreateCalendar(DateTime.Now.Year, DateTime.Now.Month, CalendarHelper.GetCalendarSettings(config, DateTime.Now.Year));
//        var selection = AnsiConsole.Prompt(
//            new SelectionPrompt<(int Index, string Description)>()
//                .Title("[green1]请选择要使用的工具：[/]")
//                .PageSize(10)
//                .UseConverter(option => $"[yellow]【{option.Description}】[/]")
//                .AddChoices(options));
//        if (selection.Index != 0)
//        {
//            ToolHelper.ReserveConsole(0, $"[bold][aqua]当前工具：【{selection.Description}】[/][/] ");
//            ToolHelper.ConsoleClear();
//        }
//        ITools? tools = null;
//        // 根据选择执行操作
//        switch (selection.Index)
//        {
//            case 1:
//                tools = new CherryPick();
//                break;

//            case 2:
//                tools = new WorkMonthlyReport();
//                break;

//            case 3:
//                tools = new HolidayStatistics();
//                break;

//            case 4:
//                tools = new Base64ToFile();
//                break;

//            case 5:
//                tools = new PDFMerge();
//                break;

//            case 0:
//                AnsiConsole.MarkupLine("[red]正在退出系统...[/]");
//                return;

//            default:
//                break;
//        }
//        tools?.ToolsMethod(config);
//    }
//    catch (Exception ex)
//    {
//        Log.Error(ex, ex.Message);
//        AnsiConsole.MarkupLine($"[red]Error:{ex.Message}\n{ex.StackTrace}[/]");
//        AnsiConsole.MarkupLine("[grey]按任意键继续...[/]");
//        Console.ReadKey();
//    }
//}